/**
 * Created by ybjaa on 2017/6/29.
 */

import {abstractValidator} from "./abstractValidator";
import {mc_validatorResult} from "../model/mc_validatorResult";
import {requireValidator} from "./requireValidator";


export class minLengthValidator extends abstractValidator{

    protected min:number=0;


    public setParameters(min:number=0): void {
        this.min=min;
        if(min<0) this.min=0;
    }

    protected getValidator(obj:string): mc_validatorResult {

        if(typeof(obj) != "string"){
            this.setResult(false,"数据类型不对");
            this.result.result=false;
        }

        //判断是否为空
        let validator=new requireValidator();
        this.setValidatorClass(validator);
        let result=validator.validator(obj);
        if(!result.result) return result;


        //判断最小长度
        if(obj.length<this.min){
            this.setResult(false,"长度小于"+this.min);
        }

        return this.result;
    }
}